﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibMinecraft.Server;

namespace PartyCraftServer.Commands
{
    public class RestartCommand : Command
    {
        public override bool RequiresOp
        {
            get { return true; }
        }

        public override string DefaultCommand
        {
            get { return "restart"; }
        }

        public override string Documentation
        {
            get { return "Restarts the server.\nUsage: /restart (reason)"; }
        }

        public override void ExecuteCommand(RemoteClient client, params string[] parameters)
        {
            string reason = "";
            if (parameters.Length != 0)
            {
                reason = parameters[0];
                for (int i = 1; i < parameters.Length; i++)
                    reason += " " + parameters[i];
            }
            else
                reason = PartyCraft.Settings["server.messages.restart"];

            foreach (RemoteClient c in PartyCraft.Server.ConnectedClients)
            {
                PartyCraft.Server.KickPlayer(c.PlayerEntity.Name, reason);
            }

            PartyCraft.AsyncAction = AsyncAction.RestartServer;
            PartyCraft.AsyncReset.Set();
        }
    }
}
